package com.he.listener;

import com.he.entity.ResultData;
import com.he.entity.RoomPrice;
import com.he.event.EventListener;
import com.he.event.constact.EventConstact;
import com.he.feign.HotelFeign;
import com.he.service.ISearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class HotelPriceEventListener implements EventListener<RoomPrice> {

    @Autowired
    private ISearchService searchService;

    @Autowired
    private HotelFeign hotelFeign;

    @Override
    public String getEventType() {
        return EventConstact.EVENT_HOTEL_PRICE_UPDATE;
    }

    @Override
    public void eventHandler(RoomPrice roomPrice) {
        System.out.println("搜索服务接收到酒店价格更新事件，" + roomPrice);
        ResultData<Integer> hidData = hotelFeign.getHotelIdByRoomId(roomPrice.getRid());
        searchService.updateRoomPrice(hidData.getData(), roomPrice);
    }
}
